package com.bdqn.controller;

import cn.hutool.core.date.DateUtil;
import com.bdqn.util.DateUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.beans.PropertyEditorSupport;
import java.util.Date;

/**
 * <Description> <br>
 *
 * @author tao<br>
 * @version 1.0<br>
 * @taskId: <br>
 * @createDate 2019/09/27 10:52 <br>
 * @see com.bdqn.controller <br>
 */
@Controller
public class BaseController {

    @InitBinder
    public void initBinder(WebDataBinder binder)
    {
        // Date 类型转换
        binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
        {
            @Override
            public void setAsText(String text)
           {
                setValue(DateUtils.parseDate(text));
            }
        });
    }
}
